vec2 fixuv(in vec2 uv) {
vec2 p =   vec2(uv.x / iResolution.x * (iResolution.x / iResolution.y), abs(uv.y / iResolution.y - 1.));
return p;
}


vec3 drawGrid(in vec2 p) {
float f = floor(p.x*10.) + floor(p.y*10.);
vec3 col = mix(vec3(0.75), vec3(0.3), smoothstep(0., 1., mod(f, 2.)));
return col;
}


// 画中心线
vec3 drawCenterLine(in vec2 p, in vec3 col) {
p = (2.0 * p - iResolution.xy) / min(iResolution.x, iResolution.y);
col = mix(col, vec3(1., 0., 0.), smoothstep(abs(p.x), abs(p.x), fwidth(p.x) * 2.));
col = mix(col, vec3(0., 0., 1.), smoothstep(abs(p.y), abs(p.y), fwidth(p.y) * 2.));
return col;
}

vec3 drawWhiteAndBlack(in vec2 p,in vec3 col){

    col= mix(vec3(0.),vec3(1.) ,mod( floor(iTime+ p.x*100.)+floor(iTime+ p.y*100.),2.));
    return col ;
}

vec3 drawDiagonalStripes(in vec2 p,in vec3 col){

    vec2 pos =  vec2(p*10.);
    
    pos.y+=iTime*2.;
    pos.x+=iTime*2.;
    float radin = 3.14/180.*45.;
    float x = fract(cos(radin)*pos.x+sin(radin)*pos.y );
    col =mix(vec3(1),vec3(0),abs(x*2.-1.));
    return col ;
}

void mainImage1( out vec4 fragColor, in vec2 fragCoord )
{
	vec2 p = (2.0*fragCoord-iResolution.xy)/min(iResolution.y,iResolution.x);
	
    // background color
    vec3 bcol = vec3(1.0,0.8,0.7-0.07*p.y)*(1.0-0.25*length(p));

    // animate
    float tt = mod(iTime,1.5)/1.5;
    float ss = pow(tt,.2)*0.5 + 0.5;
    ss = 1.0 + ss*0.5*sin(tt*6.2831*3.0 + p.y*0.5)*exp(-tt*4.0);
    p *= vec2(0.5,1.5) + ss*vec2(0.5,-0.5);

    // shape
#if 0
    p *= 0.8;
    p.y = -0.1 - p.y*1.2 + abs(p.x)*(1.0-abs(p.x));
    float r = length(p);
	float d = 0.5;
#else
	p.y -= 0.25;
    float a = atan(p.x,p.y)/3.141593;
    float r = length(p);
    float h = abs(a);
    float d = (13.0*h - 22.0*h*h + 10.0*h*h*h)/(6.0-5.0*h);
#endif
    
	// color
	float s = 0.75 + 0.75*p.x;
	s *= 1.0-0.4*r;
	s = 0.3 + 0.7*s;
	s *= 0.5+0.5*pow( 1.0-clamp(r/d, 0.0, 1.0 ), 0.1 );
	vec3 hcol = vec3(1.0,0.4*r,0.3)*s;
	
    vec3 col = mix( bcol, hcol, smoothstep( -0.01, 0.01, d-r) );

    fragColor = vec4(col,1.0);
}

void mainImage(out vec4 fragColor,in vec2 fragCoord){
vec2 p = fixuv(fragCoord);
vec3 col = drawGrid(p);
col = drawCenterLine(fragCoord,col);
col =drawWhiteAndBlack(p,col);
col =drawDiagonalStripes(p,col);
// col = drawCenterLine(fragCoord,col);

// col = vec3(p,0.);
fragColor =vec4(col,1.);
}



//  set INCLUDEPATH="%WindowsSdkDir%\Include\%WindowsSDKVersion%\um"
//  fxc DottedLine.shader /nologo /T lib_4_0_level_9_3_ps_only /D D2D_FUNCTION /D D2D_ENTRY=main /Fl DottedLine.fxlib /I %INCLUDEPATH%
//  fxc DottedLine.shader /nologo /T ps_4_0_level_9_3 /D D2D_FULL_SHADER /D D2D_ENTRY=main /E main /setprivate DottedLine.fxlib /Fo:DottedLine.txt /I %INCLUDEPATH%

